package com.instalinks.android.smspostservice.widget;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.os.Handler;

import com.instalinks.android.smspostservice.utils.AppConfig;
import com.instalinks.android.smspostservice.utils.enums.TimeOuts;

public abstract class ThinServerWidgetBase extends AppWidgetProvider {

	protected Context mContext;
	protected AppWidgetManager mAppWidgetManager;
	protected AppConfig mAppConfig;
	
	private Handler updateHandler;
	
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
    {
		this.mContext = context;
		this.mAppWidgetManager = appWidgetManager;
        this.mAppConfig = new AppConfig(context);
        
        updateHandler = new Handler();
        updateHandler.removeCallbacks(doUpdate);
        updateHandler.postAtTime(doUpdate, TimeOuts.OneSec.getValue());
    }
	
	private Runnable doUpdate = new Runnable() {
		
		@Override
		public void run() {
			updateStats();
			updateHandler.postDelayed(this, TimeOuts.TwoSec.getValue());
		}
	};
	
	protected abstract void updateStats();	
}
